package com.fungame.wordsearch;

import java.awt.Point;
/*
 * This class is the word whihc represent word in word search grid
 */
public class Word {
	static final String LETTERS = "abcdefghijklmnopqrstuvwxyz";
	String word;
	Point start;
	Point end;
	boolean[] positionTried=new boolean[4];
	Position wordPosition;
	boolean found=false;
	public boolean isFound() {
		return found;
	}

	public void setFound(boolean found) {
		this.found = found;
	}

	public Position getWordPosition() {
		return wordPosition;
	}

	public void setWordPosition(Position wordPosition) {
		this.wordPosition = wordPosition;
	}

	public enum Position {
		 horizontal(0,false),rightdiagonal(1,false),leftdiagonal(2,false),vertical(3,false);
		 int positionInt;
		 //boolean positionTried;
		 Position(int positionInt,boolean positionTried)
		 {
			 this.positionInt=positionInt;
			 //this.positionTried=positionTried;
		 }
		
	}
	public Word(String word)
	{
		this.word=word.toLowerCase();
	}
	
	public Word(String word, Point start,Point end)
	{
		this.word=word;
		this.start=start;
		this.end=end;
	}

	public String getWord() {
		return word;
	}

	public void setWord(String word) {
		this.word = word;
	}

	public Point getStart() {
		return start;
	}

	public void setStart(Point start) {
		this.start = start;
	}

	public Point getEnd() {
		return end;
	}

	public void setEnd(Point end) {
		this.end = end;
	}
	
	public boolean exhausedPosition()
	{
		for (int i = 0; i < positionTried.length; i++) {
			if(!positionTried[i]) return false;
		}
		//System.out.println("Position Exhausted");
		return true;
	}
	
	public Position getNewPosition()
	{
		int position = (int)(Math.random()*4);
		
		if(position==0)
		{
			positionTried[0]=true;
		}
		else if(position==1)
		{
			positionTried[1]=true;
		}
		else if(position==2)
		{
			positionTried[2]=true;
		}
		else if(position==3)
		{
			positionTried[3]=true;
		}
		
		
		switch(position)
		{
			case 0 : return Position.horizontal;
			case 1 : return Position.rightdiagonal;
			case 2 : return Position.leftdiagonal;
			case 3 : return Position.vertical;
			default : return Position.vertical;
		}
		
	}
	
	
}
